#ifndef VENUS_COMMON_MATH_H
#define VENUS_COMMON_MATH_H

#include <cmath>
#include <cstdlib>

#include "typedefs.h"

#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif

namespace venus {
class Math {
public:
  inline static float rad2deg(float rad) { return rad * Math::kDegPerRad; }
  inline static float deg2rad(float deg) { return deg * Math::kRadPerDeg; }
  
  template<typename T>
  inline static T square(T t) { return t * t; }

  template<typename T>
  inline static T clamp(T val, T min, T max) {
    if (val > max) val = max;
    if (val < min) val = min;
    return val;
  }

  inline static float Rand(float range) {
    return (float(rand()) / RAND_MAX) * range; 
  }

  template<typename T>
  inline static T min(T a, T b) { return a > b ? b : a; }

  template<typename T>
  inline static T max(T a, T b) { return a > b ? a : b; } 
 
  // Constants
  static const float kPi;
  static const float kHalfPi;
  static const float kQuarterPi;
  static const float kTwoPi;
  static const float kRadPerDeg;
  static const float kDegPerRad;
};
}//namespace venus

#endif

